from typing import Optional

from pydantic import BaseModel, EmailStr
from pydantic import Field


class Basic(BaseModel):
    username: str


class Login(Basic):
    """登录模型"""
    password: str


class UserInSchem(Login):
    """注册模型"""
    username: str
    password: str
    mobile: str = Field(..., min_length=11, max_length=11, description='手机号',
                    regex=r'^1(3\d|4[5-9]|5[0-35-9]|6[567]|7[0-8]|8\d|9[0-35-9])\d{8}$'
                    )


class EmailSchema(BaseModel):
    email: Optional[EmailStr]


class UserOutSchem(Basic):
    """orm 查询数据 结果 过滤"""
    id: int
    username: str
    mobile: Optional[str] = None
    email: Optional[str] = None

    class Config:
        orm_mode = True

